package com.lz.core.tcp;

import io.vertx.core.Vertx;
import io.vertx.core.net.NetClientOptions;
import io.vertx.core.net.impl.SocketAddressImpl;

/**
 * NetClient..
 *
 * @author Lizhong
 * @date 2020/5/29
 */
public class NetClient {
    public static void method01() {


        Vertx vertx = Vertx.vertx();
        NetClientOptions netServerOptions = new NetClientOptions();
        netServerOptions.setConnectTimeout(10).setReconnectAttempts(3);
        vertx
                .createNetClient(netServerOptions)
                .connect(new SocketAddressImpl(1568, "127.0.0.1"), h -> {
                    if (h.succeeded()) {
                        System.out.println(h.result().handler(h1 -> {
                            byte[] bytes = h1.getBytes();
                            System.out.println(new String(bytes));
                        }));
                        while (true) {
                            System.out.println(h.result().write("hello"));
                            try {
                                Thread.sleep(1000)
                                ;
                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            }
                        }

                    }
                });
    }


    public static void main(String[] args) {
        method01();
    }
}
